package com.yk.mr.dao.job.impl;

import com.yk.mr.dao.common.api.ICommonDAO;
import com.yk.mr.dao.job.api.IJobDAO;
import com.yk.mr.model.job.JobModel;
import org.hibernate.query.Query;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("jobDAO")
public class JobDAOImpl implements IJobDAO {
    @Resource(name = "commonDAO")
    private ICommonDAO commonDAO;
    @Override
    public JobModel queryJobById(String jobId) {
        String hql = "from JobModel as Model where Model.jobId=:jobId";
        Query<JobModel> query = this.commonDAO.getNewSession().createQuery(hql,JobModel.class);
        query.setParameter("jobId",jobId);
        return query.getSingleResult();
    }

    @Override
    public List<JobModel> queryAll() {
        String hql="from JobModel as model order by model.updateTime desc ";
        Query<JobModel> query=this.commonDAO.getSession().createQuery(hql,JobModel.class);
        return query.list();
    }

    @Override
    public List<JobModel> queryPage(int start, int limit) {
        String hql="from JobModel as model order by model.updateTime desc ";
        Query<JobModel> query=this.commonDAO.getSession().createQuery(hql,JobModel.class);
        query.setFirstResult(start);
        query.setMaxResults(limit);
        return query.list();
    }


}
